package work6;

/**
 * @TODO
 * @Author xu
 * 2025/2/28
 */
public class ScoreCalculator {
    private float javaScore;        // Java成绩
    private float cSharpScore;      // C#成绩
    private float databaseScore;     // 数据库成绩

    // 无参构造方法
    public ScoreCalculator() {
        this.javaScore = 0.0f;
        this.cSharpScore = 0.0f;
        this.databaseScore = 0.0f;
    }

    // 带参数的构造方法
    public ScoreCalculator(float javaScore, float cSharpScore, float databaseScore) {
        this.javaScore = javaScore;
        this.cSharpScore = cSharpScore;
        this.databaseScore = databaseScore;
    }

    // Getter 和 Setter 方法
    public float getJavaScore() {
        return javaScore;
    }

    public void setJavaScore(float javaScore) {
        this.javaScore = javaScore;
    }

    public float getCSharpScore() {
        return cSharpScore;
    }

    public void setCSharpScore(float cSharpScore) {
        this.cSharpScore = cSharpScore;
    }

    public float getDatabaseScore() {
        return databaseScore;
    }

    public void setDatabaseScore(float databaseScore) {
        this.databaseScore = databaseScore;
    }

    // 计算总成绩的方法
    public float calculateTotalScore() {
        return javaScore + cSharpScore + databaseScore;
    }

    // 计算平均值的方法
    public float calculateAverageScore() {
        return calculateTotalScore() / 3;
    }

    // 主方法
    public static void main(String[] args) {
        // 通过无参构造方法实例化对象
        ScoreCalculator scores1 = new ScoreCalculator();
        scores1.setJavaScore(85.5f);
        scores1.setCSharpScore(90.0f);
        scores1.setDatabaseScore(78.5f);

        // 通过有参构造方法实例化对象
        ScoreCalculator scores2 = new ScoreCalculator(88.0f, 75.0f, 92.0f);

        // 计算并打印无参构造对象的总成绩和平均值
        System.out.println("对象1: 无参构造方法");
        System.out.println("总成绩: " + scores1.calculateTotalScore());
        System.out.println("平均成绩: " + scores1.calculateAverageScore());

        // 计算并打印有参构造对象的总成绩和平均值
        System.out.println("\n对象2: 有参构造方法");
        System.out.println("总成绩: " + scores2.calculateTotalScore());
        System.out.println("平均成绩: " + scores2.calculateAverageScore());
    }
}
